<?php
/**
 * PhpStorm
 * User: zucheng
 * Date: 2019/4/12
 */

use Illuminate\Database\Seeder;

class OrderTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     * @return void
     */
    public function run()
    {
        \App\Models\Order::truncate();

        $ownerMem = \App\Models\Member::where('role_id', 20)->first();
        $sender   = \App\Models\Member::where('parent_id', $ownerMem->id)->where('role_id', 21)->first();
        $receiver  = \App\Models\Member::where('parent_id', $ownerMem->id)->where('role_id', 22)->first();

        $route  = \App\Models\OwnerRoutes::where('owner_uuid', $ownerMem->uuid)->first();

        for ($i=0; $i<5; $i++) {
            $unit = mt_rand(1, 2);

            // 生成订单
            \App\Models\Order::create([
                'order_no'        => \App\Library\Common::createOrderNo(),
                'owner_uuid'      => $ownerMem->uuid,
                'sender_uuid'     => $sender->uuid,
                'receiver_uuid'   => $receiver->uuid,
                'route_id'        => $route->id,
                'cargo_type'      => '煤炭',
                'price'           => mt_rand(1000, 2000) * 100,
                'price_unit'      => 1,
                'price_desc'      => '按重量计算',
                'loss_deduct'     => 1,
                'loss_limit'      => 1,
                'loss_price'      => mt_rand(500, 800) * 100,
                'loss_price_unit' => 1,
                'car_scheme_id'   => 1,
                'total_car_num'   => 5,
                'order_remark'    => '及时装货',
                'start_time'      => date('Y-m-d H:i:s'),
                'end_time'        => date('Y-m-d H:i:s', strtotime("+10 day")),
            ]);
        }
    }
}